using CfgTable;
using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using System;

namespace IQIGame.Onigao.GamePlay
{
    public class UIN_EquipSkinItem : UIBaseNode
    {
        #region Template Generate,don't modify
        protected class UIB_UIN_EquipSkinItem
        {
            #region ObjectBinding Generate
            public IQIGame.Onigao.Framework.ExImage imageIcon { protected set; get; }
            public IQIGame.Onigao.Framework.ExImage imageBg { protected set; get; }
            public IQIGame.Onigao.Framework.ExText textName { protected set; get; }
            public UnityEngine.GameObject select { protected set; get; }
            public IQIGame.Onigao.Framework.ExButton exBtnSelf { protected set; get; }
            public UnityEngine.GameObject lockTip { protected set; get; }
            public virtual void InitBinding(ObjectBinding __binding)
            {
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExImage>("imageIcon", out var __tbv0);
                this.imageIcon = __tbv0;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExImage>("imageBg", out var __tbv1);
                this.imageBg = __tbv1;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("textName", out var __tbv2);
                this.textName = __tbv2;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("select", out var __tbv3);
                this.select = __tbv3;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExButton>("exBtnSelf", out var __tbv4);
                this.exBtnSelf = __tbv4;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("lockTip", out var __tbv5);
                this.lockTip = __tbv5;
            }
            #endregion ObjectBinding Generate 
        }
        #endregion Template Generate,don't modify

        #region fields & properties
        private int dataIndex = -1;
        private CfgEquipSkin data = null;
        private Action<int, UIN_EquipSkinItem> callOnClick = null;

        protected UIB_UIN_EquipSkinItem ui { get; set; }
        #endregion

        protected override void BeforeInit()
        {
            ui = new UIB_UIN_EquipSkinItem();
            ui.InitBinding(this.csObjBind);
        }

        protected override void OnInit()
        {
            this.ui.exBtnSelf.onClick.AddListener(this.OnClickSelf);
        }

        protected override void OnShow()
        {

        }

        protected override void OnHide()
        {

        }

        private void OnClickSelf()
        {
            callOnClick?.Invoke(this.dataIndex, this);
        }

        protected override void OnDispose()
        {
            this.dataIndex = -1;
            this.data = null;
        }

        public void SetClickCall(Action<int, UIN_EquipSkinItem> call)
        {
            this.callOnClick = call;
        }

        public void Show(CfgEquipSkin cfg, int index)
        {
            this.Show();
            this.data = cfg;
            this.dataIndex = index;
            this.SetImageSprite(this.ui.imageIcon, cfg.Icon_fullPath);
        }

        public void SetSelected(bool isSelected)
        {
            this.ui.select.SetActive(isSelected);
        }

        public void SetUnLocked(bool isUnlocked)
        {
            this.ui.lockTip.SetActive(!isUnlocked);
        }
    }
}
